import pymysql
from pymysql import ProgrammingError

class DB:
    def __init__(self):
        self.db = pymysql.connect('localhost','root','112622','redmoonoa')
        self.cursor = self.db.cursor()

    def executeSQL(self,sql):
        result = 1
        try:
            self.cursor.execute(sql)
            self.db.commit()
        except Exception as e:
            self.db.rollback()
            print(f'sql执行失败，具体错误如下:{e}')
            print(f'本次执行的sql语句:{sql}')
            result = 0
        return result

    def close(self):
        self.db.close()